package com.lxm.config.canal;

import com.lxm.common.contants.ItemConstants;
import com.lxm.entity.ItemType;
import jakarta.annotation.Resource;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import top.javatool.canal.client.annotation.CanalTable;
import top.javatool.canal.client.handler.EntryHandler;

@Component
@CanalTable("item_type")
public class ItemTypeCanal implements EntryHandler<ItemType> {
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void insert(ItemType itemType) {
        stringRedisTemplate.opsForHash().put(ItemConstants.ITEM_TYPE_KEY,
                itemType.getId().toString(), itemType.getName());
    }

    @Override
    public void update(ItemType before, ItemType after) {
        stringRedisTemplate.opsForHash().put(ItemConstants.ITEM_TYPE_KEY,
                after.getId().toString(), after.getName());
    }

    @Override
    public void delete(ItemType itemType) {
        stringRedisTemplate.opsForHash().delete(ItemConstants.ITEM_TYPE_KEY,
                itemType.getId().toString());
    }
}
